package com.ycp.erp.main.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jakewharton.rxbinding2.view.RxView;
import com.one.common.config.CMemoryData;
import com.one.common.config.RouterPath;
import com.one.common.manager.RouterManager;
import com.one.common.manager.event.Subscribe;
import com.one.common.manager.imagchoose.ChooseManager;
import com.one.common.manager.imageloader.ILoader;
import com.one.common.manager.imageloader.LoaderManager;
import com.one.common.model.event.PicEvent;
import com.one.common.model.extra.DefaultExtra;
import com.one.common.view.base.BaseFragment;
import com.one.common.view.base.BaseFragmentActivity;
import com.ycp.erp.R;
import com.ycp.erp.login.activity.LoginActivity;
import com.ycp.erp.login.activity.LoginErpActivity;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;

/**
 * Class Des:
 * Created by bjh on 2021/8/23.
 */
public class MineFragment extends BaseFragment {
    @BindView(R.id.ivAvatar)
    ImageView ivAvatar;
    @BindView(R.id.tvLoginOrRegister)
    TextView tvLoginOrRegister;
    @BindView(R.id.ivSetting)
    ImageView ivSetting;
    @BindView(R.id.tvPoints)
    TextView tvPoints;
    @BindView(R.id.llPoints)
    LinearLayout llPoints;
    @BindView(R.id.tvWarehousing)
    TextView tvWarehousing;
    @BindView(R.id.llWarehousing)
    LinearLayout llWarehousing;
    @BindView(R.id.tvOutOfStock)
    TextView tvOutOfStock;
    @BindView(R.id.llOutOfStock)
    LinearLayout llOutOfStock;
    @BindView(R.id.gl)
    View gl;
    @BindView(R.id.tvHistory)
    TextView tvHistory;
    @BindView(R.id.line1)
    View line1;
    @BindView(R.id.tvSys)
    TextView tvSys;
    @BindView(R.id.tvLoginHint)
    TextView tvLoginHint;
    @BindView(R.id.line2)
    View line2;
    @BindView(R.id.ll1)
    LinearLayout ll1;
    @BindView(R.id.tvWelfare)
    TextView tvWelfare;
    @BindView(R.id.line3)
    View line3;
    @BindView(R.id.llEnterWarehouseRecord)
    LinearLayout llEnterWarehouseRecord;
    @BindView(R.id.llOutWarehouseRecord)
    LinearLayout llOutWarehouseRecord;
    @BindView(R.id.llMoveWarehouseRecord)
    LinearLayout llMoveWarehouseRecord;
    @BindView(R.id.llInventoryRecord)
    LinearLayout llInventoryRecord;

    @Override
    protected void initPresenter() {

    }

    @SuppressLint("CheckResult")
    @Override
    public void initView() {
        super.initView();
        RxView.clicks(ivAvatar).throttleFirst(1, TimeUnit.SECONDS).subscribe(o -> {
            ChooseManager.getChooser().chooseSingle(getActivity());
//            SelectPicBottomDialog selectPicBottomDialog =new SelectPicBottomDialog(getActivity(), new SelectPicBottomDialog.SPClickInterface() {
//                @Override
//                public void onTakePhoto() {
//                    ChooseManager.getChooser().chooseSingle(getActivity());
//                }
//
//                @Override
//                public void OnSelectPic() {
//                    ChooseManager.getChooser().chooseSingle(getActivity());
//                }
//            });
//
//            selectPicBottomDialog.show();
        });
        RxView.clicks(ivSetting).throttleFirst(500, TimeUnit.MILLISECONDS).subscribe(o -> {
            //设置
            RouterManager.getInstance().go(RouterPath.SETTING);
        });
        RxView.clicks(llEnterWarehouseRecord).throttleFirst(500, TimeUnit.MILLISECONDS).subscribe(o -> {
            RouterManager.getInstance().go(RouterPath.HISTORY,new DefaultExtra(0));
        });
        RxView.clicks(llOutWarehouseRecord).throttleFirst(500, TimeUnit.MILLISECONDS).subscribe(o -> {
            RouterManager.getInstance().go(RouterPath.HISTORY,new DefaultExtra(1));
        });
        RxView.clicks(llMoveWarehouseRecord).throttleFirst(500, TimeUnit.MILLISECONDS).subscribe(o -> {
            RouterManager.getInstance().go(RouterPath.HISTORY,new DefaultExtra(2));
        });
        RxView.clicks(llInventoryRecord).throttleFirst(500, TimeUnit.MILLISECONDS).subscribe(o -> {
            RouterManager.getInstance().go(RouterPath.HISTORY,new DefaultExtra(3));
        });
        RxView.clicks(tvLoginOrRegister).throttleFirst(500, TimeUnit.MILLISECONDS).subscribe(o -> {
            if (CMemoryData.isIsLogin()){
                //跳转到个人资料
                RouterManager.getInstance().go(RouterPath.PERSONAL_INFO);
            }else {
                //去登录页面登录
                Intent loginActivityIntent = new Intent();
                loginActivityIntent.setClass(mContext, LoginErpActivity.class);
                loginActivityIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                mActivity.startActivity(loginActivityIntent);
            }

        });
        if (CMemoryData.isIsLogin()){
            tvLoginOrRegister.setText("张三");
            tvLoginHint.setVisibility(View.GONE);
        }

    }

    @Subscribe
    public void pic(PicEvent event) {
//        if (uploadDialog==null){
//            uploadDialog=new LoadingDialog(getActivity());
//        }
        if (event != null) {
            ILoader.Options options = ILoader.Options.circleOptions();
            options.loadingResId = R.mipmap.ic_default_avatar;
            options.loadErrorResId = R.mipmap.ic_default_avatar;
            LoaderManager.getLoader().loadNet(ivAvatar, event.getPath(),
                    options);
//            mPresenter.uploadImageFile(UploadType.TYPE_15,event.getPath());
        }
    }

    @Override
    public int getLayoutResId() {
        return R.layout.fragment_mine;
    }
}
